import os

import matplotlib.pyplot as plt
import matplotlib.animation as animation

import numpy as np


from pyx_package.script import BaseBehavior
from pyx_package.ps_paramete import PsParameter
PYX_MODULE_NAME = "文件夹解析"

class ScriptBehavior(BaseBehavior):

    def __init__(self) -> None:
        super().__init__()
        
        self.SetExeMode("process")

    
    def Start(self):

        drawanimationhist()
        
        self.Debug("进程已经退出", "warning")
        self.Finish()


def drawanimationhist():
    fig, ax = plt.subplots()
    BINS = np.linspace(-5, 5, 100)
    data = np.random.randn(1000)
    n, _ = np.histogram(data, BINS)
    _, _, bar_container = ax.hist(data, BINS, lw=2,
                                  ec="b", fc="pink")
    def update(bar_container):
        def animate(frame_number):
            data = np.random.randn(1000)
            n, _ = np.histogram(data, BINS)
            for count, rect in zip(n, bar_container.patches):
                rect.set_height(count)
            return bar_container.patches
        return animate
 
    ax.set_ylim(top=55)
 
    ani = animation.FuncAnimation(fig, update(bar_container), 120,
                                  repeat=False, blit=True)
    plt.show()